<template>
    <!-- 总包签证报送审批 -->
    <base-breadcrumb :title="$route.meta.title">
        <!-- 搜索 -->
        <searchData :searchData="searchArr" @search="search"></searchData>
        <!-- 表格 -->
        <a-card :bordered="false">
            <!-- <title-name :title="$route.meta.title"></title-name> -->
            <a-button class="mb12" icon="plus" type="primary" @click="handleManage(2)" v-btnPermission="'bm_027_add_01'"
                >新增</a-button
            >
            <a-alert class="mb12" type="info" show-icon>
                <template slot="message">
                    <span>
                        报送份数：
                        <a>{{ statistics.sendCount }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        报送金额(含税)(万元)：
                        <a>{{ statistics.submitMoney }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        保底值(含税)(万元)：
                        <a>{{ statistics.floorMoney }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        对应成本(含税)(万元)：
                        <a>{{ statistics.correspondingCost }}</a>
                    </span>
                    <a-divider type="vertical" />
                    <span>
                        保底利润率(%)：
                        <a>{{ statistics.floorRateOfProfit }}</a>
                    </span>
                </template>
            </a-alert>
            <!-- 表格 -->
            <list-table
                ref="table"
                tableLayout="fixed"
                :pageKeys="['pageNum', 'pageSize', 'totalSize']"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
            >
                <template slot="action" slot-scope="text, record">
                     <MoreButton>
                    <a @click="handleManage(0, record)" v-btnPermission="'bm_027_loo_04'">查看</a>
                    <span
                        v-if="
                            record.auditStatus != 'SUBMITTED' &&
                            record.auditStatus != 'PAST' &&
                            record.auditStatus != 'ABOLISH'
                        "
                        v-btnPermission="'bm_027_edi_02'"
                    >
                        <a @click="handleManage(1, record)">编辑</a>
                    </span>
                    <!-- {{record}} -->
                    <span v-if="record.auditStatus == 'SUBMITTED'&&selfBtnShow(record.createUserId)&&hideBuquBtn()">
                        <a @click="handleUndo({ id: record.id, type: 3 })">撤销</a>
                    </span>
                    <span v-if="record.auditStatus == 'PAST'" v-btnPermission="'bm_027_tov_05'">
                        <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
                    </span>
                    <template v-if="record.auditStatus === 'REJECTED'">
                        <template>
                            <span
                                v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'"
                                v-btnPermission="'bm_027_del_03'"
                            >
                                <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
                            </span>
                            <span
                                v-if="
                                    record.auditStatus === 'PAST' ||
                                    record.auditStatus === 'SUBMITTED' ||
                                    record.auditStatus === 'REJECTED' ||
                                    record.auditStatus === 'ABOLISH'
                                "
                                v-btnPermission="'bm_027_loo_04'"
                            >
                                <approval-button :id="record.id" :status="record.auditStatus" />
                            </span>
                        </template>
                    </template>
                    <!-- 删除 -->
                    <template v-else
                        ><span
                            v-if="record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED'"
                            v-btnPermission="'bm_027_del_03'"
                        >
                            <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>
                        </span>

                        <span
                            v-if="
                                record.auditStatus === 'PAST' ||
                                record.auditStatus === 'SUBMITTED' ||
                                record.auditStatus === 'REJECTED' ||
                                record.auditStatus === 'ABOLISH'
                            "
                            v-btnPermission="'bm_027_loo_04'"
                        >
                            <approval-button :id="record.id" :status="record.auditStatus" /> </span
                    ></template>

                     </MoreButton>
                </template>
                <template slot="auditStatus" slot-scope="text, record">
                    <list-status :status="record.auditStatus" conversion="en" :is-approval="true" :text="text" />
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import { STable } from '@/components' // 表格
import {
    getPageCommercialVisaSendApprove,
    delCommercialVisaSendApprove,
    revokeCommercialVisaSendApprove,
    undoCommercialVisaSendApprove,
    getCommercialVisaSendApproveCount
} from '@/api/businessAffairs/lumpSumMeasurement'
import BasePage from '@/views/basePage' // 基础配置
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { typeListApproval } from '@/utils/util'
import { types, status } from './model'
import MoreButton from '@/components/MoreButton'
const searchArr = [
    // 搜索框
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany
    // },
    // {
    //     name: '项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject
    // },
    {
        name: '签证名称',
        type: 'input',
        value: 'visaName'
    },
    {
        name: '类型',
        value: 'typleId',
        type: 'select',
        data: types
    },
    {
        name: '报送时间',
        type: 'dateRange',
        value: 'submitDate',
        attr: {
            rangeFormat: ['submitStartTime', 'submitEndTime']
        }
    },
    {
        name: '填报人',
        type: 'input',
        value: 'updateUserName'
    },
    {
        name: '填报时间',
        type: 'dateRange',
        value: 'activityDate',
        attr: {
            rangeFormat: ['updateStartTime', 'updateEndTime']
        }
    },
    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: [
            {
                value: '0',
                label: '待提交审批'
            },
            {
                value: '1',
                label: '审批中'
            },
            // {
            //     value: '2',
            //     label: '资料上传中'
            // },
            {
                value: '3',
                label: '审批通过'
            },
            {
                value: '5',
                label: '审批不通过'
            },
            {
                value: '4',
                label: '已作废'
            }
        ]
    }
]

const columns = [
    // {
    //     title: '序号',
    //     width: 80,
    //     dataIndex: 'index',
    //     customRender() {
    //         return arguments[2] + 1
    //     }
    // },
    {
        title: '所属分公司',
        dataIndex: 'branchComName'
    },

    {
        title: '所属项目',
        dataIndex: 'projectName',

        ellipsis: true
    },
    {
        title: '签证名称',
        dataIndex: 'visaName',

        ellipsis: true
    },

    {
        title: '类型',
        dataIndex: 'typleName'
    },
    {
        title: '签证编号',
        dataIndex: 'visaId',
        ellipsis: true
    },
    {
        title: '报送时间',
        dataIndex: 'submitTime'
    },
    {
        title: '报送金额(含税)(万元)',
        dataIndex: 'submitMoneyHaveVat',
        customRender() {
            return arguments[1].measureDetailDefine[0].addedTaxFee
        }
    },
    {
        title: '保底值(含税)(万元)',
        dataIndex: 'floorMoneyHaveVat',
        customRender() {
            return arguments[1].measureDetailDefine[1].addedTaxFee
        }
    },
    {
        title: '对应成本(含税)(万元)',
        dataIndex: 'correspondingCostHaveVat',
        customRender() {
            return arguments[1].measureDetailDefine[2].addedTaxFee
        }
    },
    {
        title: '保底利润率%',
        dataIndex: 'floorRateOfProfit'
    },
    {
        title: '填报人',
        dataIndex: 'updateUserName'
    },
    {
        title: '填报时间',
        dataIndex: 'updateTime'
    },
    {
        title: '状态',
        dataIndex: 'auditStatus',
        scopedSlots: { customRender: 'auditStatus' }
    },
    {
        title: '操作',
        dataIndex: 'action',
        fixed: 'right',
        width: '180px',
        align: 'center',
        scopedSlots: { customRender: 'action' }
    }
]
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    components: {
        STable,
        MoreButton
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {}, // 查询参数
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            statistics: { correspondingCost: 0, floorMoney: 0, floorRateOfProfit: 0, sendCount: 0, submitMoney: 0 }, //统计
            loadData: async (parameter) => {
                const requestParameters = Object.assign({}, parameter, { param: this.queryParam })
                this.getCommercialVisaSendApproveCountReq(requestParameters)
                return getPageCommercialVisaSendApprove(requestParameters).then((res) => {
                    if (res.code === '0') {
                        res.data.list.forEach((i) => {
                            i.auditStatus = status[i.auditStatus]
                        })
                        return {
                            code: 200,
                            data: res.data.list,
                            totalSize: res.data?.total,
                            currentPage: res.data?.pageNum
                        }
                    }
                })
            },
            removeApi: {
                remove: delCommercialVisaSendApprove,
                invalid: revokeCommercialVisaSendApprove,
                undo: undoCommercialVisaSendApprove
            } // api
        }
    },
    methods: {
        getCommercialVisaSendApproveCountReq(requestParameters) {
            getCommercialVisaSendApproveCount(requestParameters).then((res) => {
                this.statistics = res.data
            })
        },
        // 搜索
        search(value) {
            value && (this.queryParam = value)
            this.$refs.table.refresh(true)
        },
        // 操作栏
        handleManage(type, record) {
            let query = {
                editModel: type
            }
            if (record && record.id) {
                query.id = record.id
            }
            this.$router.push({
                name: 'updateVisaApproval',
                query
            })
        }
    }
}
</script>
